home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / ACCTYEAR.PRG < prev    next >
Text File  |  1992-09-28  |  3KB  |  104 lines

  1. /*
  2.  * File......: ACCTYEAR.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS ID....: 74731,1751
  5.  * Date......: $Date:   28 Sep 1992 00:29:14  $
  6.  * Revision..: $Revision:   1.3  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/acctyear.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   C:/nanfor/src/acctyear.prv  $
  16.  * 
  17.  *    Rev 1.3   28 Sep 1992 00:29:14   GLENN
  18.  * Jo French clean up.
  19.  * 
  20.  *    Rev 1.2   15 Aug 1991 23:02:40   GLENN
  21.  * Forest Belt proofread/edited/cleaned up doc
  22.  * 
  23.  *    Rev 1.1   14 Jun 1991 19:50:48   GLENN
  24.  * Minor edit to file header
  25.  * 
  26.  *    Rev 1.0   01 Apr 1991 01:00:28   GLENN
  27.  * Nanforum Toolkit
  28.  *
  29.  */
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *     FT_ACCTYEAR()
  34.  *  $CATEGORY$
  35.  *     Date/Time
  36.  *  $ONELINER$
  37.  *     Return accounting year data
  38.  *  $SYNTAX$
  39.  *     FT_ACCTYEAR( [ <dGivenDate> ] ) -> aDateInfo
  40.  *  $ARGUMENTS$
  41.  *     <dGivenDate> is any valid date in any date format.  Defaults
  42.  *     to current system date if not supplied.
  43.  *  $RETURNS$
  44.  *     A three element array containing the following data:
  45.  *
  46.  *        aDateInfo[1] - The year as a character string "YYYY"
  47.  *        aDateInfo[2] - The beginning date of the accounting year
  48.  *        aDateInfo[3] - The ending date of the accounting year
  49.  *  $DESCRIPTION$
  50.  *     FT_ACCTYEAR() creates an array containing data about the
  51.  *     accounting year containing the given date.
  52.  *
  53.  *     An accounting period has the following characteristics:
  54.  *
  55.  *     If the first week of the period contains 4 or more 'work'
  56.  *     days, it is included in the period; otherwise, the first
  57.  *     week was included in the prior period.
  58.  *
  59.  *     If the last week of the period contains 4 or more 'work'
  60.  *     days it is included in the period; otherwise, the last week
  61.  *     is included in the next period.  This results in 13 week
  62.  *     'quarters' and 4 or 5 week 'months'.  Every 5 or 6 years, a
  63.  *     'quarter' will contain 14 weeks and the year will contain 53
  64.  *     weeks.
  65.  *  $EXAMPLES$
  66.  *     // get info about accounting year containing 9/15/90
  67.  *     aDateInfo := FT_ACCTYEAR( CTOD("09/15/90") )
  68.  *     ? aDateInfo[1]   //  1990
  69.  *     ? aDateInfo[2]   //  12/31/89    beginning of year
  70.  *     ? aDateInfo[3]   //  12/29/90    end of year
  71.  *  $SEEALSO$
  72.  *     FT_DATECNFG() FT_ACCTWEEK() FT_ACCTMONTH() FT_ACCTQTR()
  73.  *  $END$
  74. */
  75.  
  76. FUNCTION FT_ACCTYEAR(dGivenDate)
  77.  
  78.   LOCAL nYTemp, aRetVal
  79.  
  80.   IF( VALTYPE(dGivenDate) != 'D', dGivenDate := DATE(), )
  81.  
  82.   aRetVal    := FT_YEAR(dGivenDate)
  83.   nYTemp     := VAL(aRetVal[1])
  84.   aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  85.   aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  86.  
  87.   IF dGivenDate < aRetVal[2]
  88.     aRetVal    := FT_YEAR(FT_MADD(dGivenDate, -1))
  89.     nYTemp --
  90.     aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  91.     aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  92.   ELSEIF dGivenDate > aRetVal[3]
  93.     aRetVal    := FT_YEAR(FT_MADD(dGivenDate, 1))
  94.     nYTemp ++
  95.     aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  96.     aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  97.   ENDIF
  98.  
  99.   aRetVal[1] := STR(nYTemp,4)
  100.  
  101. RETURN aRetVal
  102.  
  103.  
  104.